
// test_device_sdkDlg.h : 头文件
//

#pragma once
#include "afxcmn.h"

#include "CriticalSection.h"
#include "AviFile.h"

// download media file request
typedef struct st_event_download_file_tag
{
	char			deviceId[64]; 		// device id
	int				center;		  		// 0 device 1 center
	char			szSourcePath[260];	// source file path
	long long		llFileSize;	  		// file size
	int				nType;		  		// file type: 1 jpg, 2 video
	long long		llStartOffset;		// file offset bytes to start download
	long long		llBlockLen;	  		// block length of request to download
	int				nOffsetFlag;		// 0 - full file, 1 - size offset, 2 - time offset
	char			szStartTime[32];	// start time, format "171214 000000", time offset
	char			szEndTime[32];		// end time, format "235959"
}st_event_download_file;

// Ctest_device_sdkDlg 对话框
class Ctest_device_sdkDlg : public CDialogEx
{
// 构造
public:
	Ctest_device_sdkDlg(CWnd* pParent = NULL);	// 标准构造函数

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_TEST_DEVICE_SDK_DIALOG };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持


// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

public:
	afx_msg void OnBnClickedButtonStart();
	afx_msg void OnBnClickedButtonStop();
	afx_msg void OnBnClickedButtonOpenstream();
	afx_msg void OnBnClickedButtonClosestream();
	afx_msg void OnTimer(UINT_PTR nIDEvent);

	virtual BOOL DestroyWindow();

	void addInfo(const char* strEvent);

	CST_Decode*			m_pDecode;						//解码对象
	int					m_nDec;
	
	CInterCriSec		m_objLock;			//锁
	vector<string>		m_vtInfo;

	bool				m_bTalk;

	CAviFile			m_objAvi;
	FILE*				m_pFile;

	st_event_download_file m_stDownloadRequest;	// download file parameter
	void *				m_hDownload;

	afx_msg void OnBnClickedButtonOpentalk();
	afx_msg void OnBnClickedButtonClosetalk();
	afx_msg void OnBnClickedButtonGetgps();
	afx_msg void OnBnClickedButtonStopgps();
	afx_msg void OnBnClickedButtonQuery();
	afx_msg void OnBnClickedButtonClosequery();
	afx_msg void OnBnClickedButtonSnap();
	afx_msg void OnBnClickedButtonClosesnap();
	afx_msg void OnBnClickedButtonOpenreplay();
	afx_msg void OnBnClickedButtonClosereplay();
	afx_msg void OnBnClickedButtonDownsnap();
	afx_msg void OnBnClickedButtonClosedownsnap();
	afx_msg void OnBnClickedButtonUpgrade();
	afx_msg void OnBnClickedButtonCloseupgrade();
	afx_msg void OnBnClickedButtonGetiostatus();
	afx_msg void OnBnClickedButtonIoctrl();
	afx_msg void OnBnClickedButtonPtz();
	afx_msg void OnBnClickedButtonTrans();
	afx_msg void OnBnClickedButtonGetalarm();
	afx_msg void OnBnClickedButtonStopalarm();
	afx_msg void OnBnClickedButtonPtzTwo();
	afx_msg void OnBnClickedButtonSearch();
	afx_msg void OnBnClickedButtonDirectopenstream();
	afx_msg void OnBnClickedButtonDirectclosestream();
	afx_msg void OnBnClickedButtonDirectptz();
	afx_msg void OnBnClickedButtonStopsearch();
	afx_msg void OnBnClickedButtonGetcolour();
	afx_msg void OnBnClickedButtonSetcolour();
	afx_msg void OnBnClickedButtonExtconfig();
	afx_msg void OnBnClickedButtonGetdevinfo();

public:
	int DealEvent(long long llUserData, const char* strEvent, int nEventType);

private:
	int AnalyzeJsonEvent(int nEventType, const char *szEvent, st_event_download_file *pRequest);
	int DownloadFile(st_event_download_file *pRequest);
	int DownloadVideo(st_event_download_file *pRequest);

public:
	CListCtrl m_ctrlInfo;
};
